package com.example.w_library.log.fromat;

/**
 * 格式化接口实现类
 * 堆栈格式化
 */
public class WStackTraceFormatter implements WLogFormatter<StackTraceElement[]>{

    @Override
    public String format(StackTraceElement[] data) {

        StringBuilder sb = new StringBuilder(128);

        if (data == null || data.length == 0){
            return null;
        }else if (data.length == 1){
            return "\t- " + data[0].toString();
        }else {
            for (int i = 0; i < data.length; i++) {

                if (i == 0){
                    sb.append("'\n'---stackTrace---'\n'");
                }

                sb.append("\t |- ");
                sb.append(data[i].toString());
                sb.append("\n");

                if (i == data.length -1){
                    sb.append("\t ^ ");
                    sb.append(data[i].toString());
                }
            }

            return sb.toString();
        }
    }
}
